package com.example;

import com.mysql.jdbc.StringUtils;

/**
 * Created by Administrator on 2017/2/16.
 */
public class Leetcode_5 {
    public String longest(String s){
        String result="";
        if(s.equals("")) return result;
        for (int i=0;i<s.length()-1;i++){
            String tmp1 = check(s,i,i);
            if(tmp1.length()>result.length()){
                result=tmp1;
            }
            String tmp2 = check(s,i,i+1);
            if(tmp2.length()>result.length()){
                result=tmp2;
            }
        }
        return result;
    }
    public String check(String s,int i,int j){
        int n = s.length();
        while( i>=0 && j<= n-1 && (s.charAt(i)==s.charAt(j))){
            i--;
            j++;
        }
        return s.substring(i+1,j);
    }

    public static void main(String[] args) {
        System.out.println(new Leetcode_5().longest("cbbd"));
    }
}
